<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>制定安全库存配置单</title>
    <style>
        input{
            border-top: none;
            border-left: none;
            border-right: none;
            border-bottom: black solid 1px;
        }
        table tr th,td{
            border: 1px solid black;
            text-align: center;
        }

        table{
            border: 1px;
            cell-padding:0;
            cell-spacing:0;
            width: 80%;
            margin-top: 20px;
        }
        table thead{
            background-color:#b3d7ff ;
        }
    </style>

    <link rel="stylesheet" href="../css/pintuer.css">
    <link rel="stylesheet" href="../css/admin.css">
    <link rel="stylesheet" href="../css/bootstrap.css">

    <script src="../js/jquery-3.4.1.min.js"></script>
    <script src="../js/bootstrap-table1.15.3.js"></script>
    <script src="../js/bootstrap-table-zh-CN.min.js"></script>
    <script src="../js/popper.min.js"></script>
    <script src="../js/bootstrap.min.js"></script>
</head>

<script>

    function initConfigurationSheet() {
        /*JunM*/
        $('#configurationSheetTableInfo').bootstrapTable(
            {
                //请求方式
                method:'post',
                contentType:'application/json',
                url:'/dFile/queryConfigurationSheet.action',
                //设置交替样式
                striped:true,
                //初始显示页号
                pageNumber:1,
                //是否显示分页
                pagination:true,
                //是否设置服务端分页还是客户端分页
                sidePagination:'server',
                //页面大小
                pageSize:3,
                //分页列表
                pageList:[1,3,5,6,10],
                //上传到到服务端的参数
                queryParams:function (pares) {
                    return{
                        //计算页号（当前页）
                        pageNum:(pares.offset/pares.limit)+1,
                        //计算页大小
                        pageSize:pares.limit,
                    }
                },
                //第一列名
                columns:[
                    {title:"产品编号",field:"PRODUCT_ID",align:"center"},
                    {title:"产品名称",field:"PRODUCT_NAME",align:"center"},
                    {title:"用途类型",field:"TYPE",align:"center",formatter:function (value,row,index) {
                            if(value == 'Y001-1'){
                                return '商品'
                            }else if(value == 'Y001-2'){
                                return '物料'
                            }
                        }},
                    {title:"档次级别",field:"PRODUCT_CLASS",align:"center",formatter:function (value,row,index) {
                            if(value == 'D001-1'){
                                return '高档'
                            }else if(value == 'D001-2'){
                                return '中档'
                            }else if(value == 'D001-3'){
                                return '低档'
                            }
                        }},
                    {title:"I级分类",field:"FIRST_KIND_NAME",align:"center"},
                    {title:"II级分类",field:"SECOND_KIND_NAME",align:"center"},
                    {title:"III级分类",field:"THIRD_KIND_NAME",align:"center"},
                    {title:"制定",field:"DESIGN_CELL_TAG",align:"center",formatter:function (value,row,index) {
                            return "<a href='#' onclick='updateSCell("+JSON.stringify(row)+")' data-toggle='modal' data-target='#configurationSheetModal'>制定</a>"
                        } }
                ]
            })

    }

    //查询出已经审核通过的，且没有被设计的
    $(function () {
        initConfigurationSheet();

        //往SCell中添加数据，且修改DFile中的DESIGN_CELL_TAG	改为K001-1: 已设计
        $('#addSCellBtn').click(function () {

            let formValues = $('#addSCellFormId').serialize();
            // alert(formValues);
            let splitId = $('#kindId').text().split('-');
            // alert(split[0])
            formValues=formValues+'&firstKindId='+splitId[0]+'&secondKindId='+splitId[1]+'&thirdKindId='+splitId[2];
            // alert(formValues)
            let splitName = $('#kindName').text().split('-');
            formValues=formValues+'&firstKindName='+splitName[0]+'&secondKindName='+splitName[1]+'&thirdKindName='+splitName[2];
            $.ajax({
                type:'post',
                url:'/sCell/addSCell',
                data:formValues,
                success:function () {
                    alert('制定成功...');
                    $('#configurationSheetModal').modal('hide');
                    $('#configurationSheetTableInfo').bootstrapTable('refresh');
                },
                error:function (data) {
                    alert(data+"制定失败...")
                }
            })
        });
    })

    //把列表中的值，拿到模态框中
    function updateSCell(rows) {
        $('#tbodyId').empty();
        $(":input","#addSCellFormId")
            .not(":button",":reset","hidden","submit")
            .val("")
            .removeAttr("checked")
            .removeAttr("selected");

        $('#productName').val(rows.PRODUCT_NAME);
        $('#productId').val(rows.PRODUCT_ID);

        $('#designer').val(rows.REGISTER)

        $('#checker').val(rows.REGISTER)

        //表格
        var trObj=$('#tbodyId').append($('<tr>'));
        trObj.append($('<td>').text(1));
        trObj.append($('<td>').text("成品库"));
        trObj.append($('<td id="kindId">').text(rows.FIRST_KIND_ID+"-"+rows.SECOND_KIND_ID+"-"+rows.THIRD_KIND_ID));
        trObj.append($('<td id="kindName">').text(rows.FIRST_KIND_NAME+"-"+rows.SECOND_KIND_NAME+"-"+rows.THIRD_KIND_NAME));
        // trObj.append($('<td>').html('<input style="border: none;width: 60px;">'));
        trObj.append($('<td align="left">').html('<input name="maxCapacityAmount" id="maxCapacityAmount" style="width: 60px;">'));
        // trObj.append($('<td>').html('<input style="border: none;width: 60px;">'));

        var today=new Date();
        let year = today.getFullYear();
        let month = today.getMonth();
        let date = today.getDate();
        let hours = today.getHours();
        let minutes = today.getMinutes();
        let seconds = today.getSeconds();
        today=year+"-"+(month+1)+"-"+date+" "+hours+":"+minutes+":"+seconds;
        $('#registerTime').val(today);
        $('#checker').val(localStorage.getItem("userName"));
    }

</script>


<body bgcolor="#f5f5f5">
    <div class="container-fluid">
        <div style="width: 100%;margin: 0px;padding: 0px">
            <table id="configurationSheetTableInfo" class="table table-bordered table-hover table-striped table-condensed">

            </table>
    </div>

    <!--模态框-->
    <!--modal fade-->
    <div class="modal  fade" id="configurationSheetModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog" style="width: 90%">
            <div class="modal-content" style="border: 1px solid black;">
                <div class="modal-header">
                    <div class="container">
                        <div class="row">
                            <div class="col-7" style="text-align: right">
                                <h5 class="modal-title" id="info" >
                                    安全库存配置单
                                </h5>
                            </div>
                            <div class="col-4" style="position: absolute;right: 30px">
                                <!--<button class="btn btn-primary">添加工序</button>
                                <button class="btn btn-warning">删除工序</button>
                                <button class="btn btn-primary">预览</button>-->
                            </div>
                        </div>
                    </div>
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true" style="margin-right: 0px">

                    </button>


                </div>
                <div class="modal-body">
                    <form id="addSCellFormId">
                        <div class="container">
                            <div class="row">
                                <div class="col-2" style="text-align:right">
                                    产品名称：
                                </div>
                                <div class="col-4">
<!--                                    <span id="productName"></span>-->
                                    <input style="border: none;background-color: white;" name="productName" id="productName">
                                </div>
                                <div class="col-2" style="text-align:right">
                                    产品编号：
                                </div>
                                <div class="col-4">
<!--                                    <span id="productId" ></span>-->
                                    <input style="border: none;background-color: white;" name="productId" id="productId">
                                </div>
                            </div>
                        </div>
                        <br>
                        <div class="container-fluid">
                            <div class="row">
                                <div class="col-2" style="text-align: right">
                                    <span>库存报警下限数：</span>
                                </div>
                                <div class="col-4">
                                    <input class="form-control form-small" style="width: 300px" placeholder="库存报警下限数"  name="minAmount" id="minAmount"><br>
                                </div>
                                <div class="col-2" style="text-align: right">
                                    <span>库存报警上限数：</span>
                                </div>
                                <div class="col-4">
                                    <input class="form-control form-small" style="width: 300px" placeholder="库存报警上限数"  name="maxAmount" id="maxAmount"><br>
                                </div>
                            </div>
                        </div>
                        <div class="container-fluid">
                            <div class="row">
                                <div class="col-2" style="text-align: right">
                                    <span>设计人：</span>
                                </div>
                                <div class="col-4">
                                    <input class="form-control form-small" style="width: 300px" placeholder="设计人"  name="designer" id="designer"><br>
                                </div>
                            </div>
                        </div>
                        <table border="1" cellpadding="0" cellspacing="0" width="80%" style="margin-top: 20px;" class="table table-sm">
                            <thead  style="background-color: #b3d7ff;">
                                <tr>
                                    <th>序号</th>
                                    <th>库存名称</th>
                                    <th>存储地址编号</th>
                                    <th>存储地址名称</th>
<!--                                    <th>存储单元简称</th>-->
                                    <th>最大存储量</th>
<!--                                    <th>存储单位</th>-->
                                </tr>
                            </thead>
                            <tbody id="tbodyId">

                            </tbody>
                        </table><br>
                        <div class="container">
                            <div class="row">
                                <div class="col-2" style="text-align:right">
                                    登记人：
                                </div>
                                <div class="col-4">
                                    <input class="form-control" style="width: 200px;" placeholder="登记人" name="checker" id="checker">
                                </div>
                                <div class="col-2" style="text-align:right">
                                    登记时间：
                                </div>
                                <div class="col-4">
                                    <input class="form-control form-small" style="width: 200px;border: none;background-color: white;" name="registerTime" id="registerTime">
<!--                                    <span id="checkTime"></span>-->
                                </div>
                            </div>
                        </div><br>
                        <span style="margin-left: 55px">配置要求：</span>
                        <textarea name="config" style="width: 550px;margin-left: 150px" class="form-control">

                        </textarea>

                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭
                    </button>
                    <button type="button" class="btn btn-primary" id="addSCellBtn">
                        制定
                    </button>
                </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal -->
    </div>
    </div>
</body>
</html>